Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure MaxBy/MinBy return first element if all keys are null. #61364

Merged
merged 1 commit into from
Nov 9, 2021

Conversation

eiriktsarpalis
Copy link
Member

@eiriktsarpalis eiriktsarpalis commented Nov 9, 2021

Following the null handling semantics of the Max and Min methods, the new MaxBy and MinBy methods have been designed to skip any elements yielding null keys. As a side-effect of the behavior, the methods will return the last element in a sequence if every key turns out to be null. While this does not produce any observable difference in the Max and Min methods, it does do so in the MaxBy and MinBy case. In fact it is inconsistent with how the same methods treat sequences returning identical non-null keys, where the first element is always favored.

I do not believe this to be a breaking change, since our documentation provides no guarantee on what element will get returned in the event of a tie.

Fixes #61317.

@eiriktsarpalis eiriktsarpalis added this to the 7.0.0 milestone Nov 9, 2021
@eiriktsarpalis eiriktsarpalis self-assigned this Nov 9, 2021
@ghost
Copy link

ghost commented Nov 9, 2021

Tagging subscribers to this area: @dotnet/area-system-linq
See info in area-owners.md if you want to be subscribed.

Issue Details

Following the null handling semantics of the Max and Min methods, the new MaxBy and MinBy methods have been designed to skip any elements yielding null keys. As a side-effect of the behavior, the methods will return the last element in a sequence if every key turns out to be null. While this does not produce any observable difference in the Max and Min methods, it does do so in the MaxBy and MinBy. In fact it is inconsistent with how the same methods treat sequences returning identical non-null keys, where the first element is always favored.

I do not believe this change to be a breaking change, since our documentation provides no guarantee on what element will get returned in the event of a tie.

Author: eiriktsarpalis
Assignees: eiriktsarpalis
Labels:

area-System.Linq

Milestone: 7.0.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MaxBy inconsistent results with tie-breaks
2 participants